package cn.mawenda.docker.task;

import cn.mawenda.docker.service.ContainerMonitorLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 * @Author: Ma.wenda
 * @Date: 2024-05-17 14:47
 * @Version: 1.0
 **/
@Component
@Slf4j
public class ContainerMonitorLogTask {


    @Resource
    private ContainerMonitorLogService containerMonitorLogService;

    @Value("#{'${docker.containerNames}'.split(',')}")
    private List<String> containerNames;

    @Scheduled(fixedRate = 60000) // 每60秒触发一次
    public void executeTask() {
        if(CollectionUtils.isEmpty(containerNames)){
            log.error("ContainerMonitorLogTask-executeTask, containerNames is null");
            return;
        }
        containerNames.forEach(containerName ->{
            containerMonitorLogService.containerMonitorStatistics(containerName);
        });

    }

}
